<template>
  <el-form
    :model="model.formData"
    ref="formRef"
    @submit.prevent
    :rules="formRules"
    label-width="140px"
  >
    <el-row>
      <el-col :xl="16" :lg="24">
        <el-form-item
          label="审批意见"
          prop="isApprove"
        >
          <el-radio-group v-model="model.formData.isApprove">
            <el-radio label="1">同意</el-radio>
            <el-radio label="0">不同意</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-col>

      <el-col :xl="16" :lg="24">
        <el-form-item label="备注" >
          <el-input
            type="textarea"
            v-model="model.formData.remark"
            :rows="3"
          ></el-input>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<script lang="ts" setup>
import { ref, reactive,watch,defineExpose } from "vue";
import {useRoute } from "vue-router";
const props = defineProps({
  projectInfo: {
    type: Object,
    default:()=>{}
  }
});
const route = useRoute();
const formRef = ref<HTMLFormElement | null>(null) as any;
const flowType = route.query.flowType;
let projectInfo = ref(null);

const formRules = ref({
  isApprove: [
    { required: true, message: "请选择审批意见", trigger: "change" }
  ]
});
const model = reactive({
  flowType: flowType,
  formData: {
    isApprove: "",
    remark: ""
  },
});

const validate = async () => {
  const isValid = await new Promise(resolve =>
    formRef.value.validate(resolve)
  );
  return isValid;
};

const initInfo = () => {
  model.formData.isApprove = projectInfo.value.isApprove;
  model.formData.remark = projectInfo.value.remark;
};

watch(
  () => props.projectInfo,
  newVal => {
    projectInfo.value = newVal;
    initInfo()
  },
  {deep:true}
);

defineExpose({
  validate,
  model
});

</script>

<style lang="scss" scoped>
.empt-content {
  height: calc(100vh - 200px);
  width: 100%;
}
.card-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .header-btn {
    font-size: 14px;
    cursor: pointer;
  }
}
</style>
